<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>商品列表</title>
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.2.0.js"></script>
    <script type="text/javascript">
        function doMiaosha(obj) {
            /*<![CDATA[*/
                var userPhone = [[${session.user.phone}]];
            /*]]>*/
            var goodsId = $(obj).attr("name");
            $.ajax({
                type:"post",
                url:"doSecKill.do",
                dataType:"json",
                data:{userPhone:userPhone,goodsId:goodsId},
                success:function (data) {
                    alert(data.msg);
                    if (data.code == "1"){
                        $.ajax({
                            type:"post",
                            url:"msResult.do",
                            dataType:"json",
                            data:{userPhone:userPhone,goodsId:goodsId},
                            success:function (datas) {
                                alert(datas.msg);
                            }
                        });
                    }
                }
            });
        }
    </script>
</head>
<body>
<h1>商品列表</h1>
<h3 th:text="'当前登陆用户:'+${session.user.getName()}+'电话:'+${session.user.getPhone()}"></h3>
<hr>
<h4 th:text="'当前系统消息:'+${msg}+'  当前系统时间:'+${#dates.format(#dates.createNow(),'yyyy-MM-dd HH:mm:ss')}"></h4>

<h4 th:text="${good_msg}"></h4>
<table border="1">
    <tr>
        <td>序号</td>
        <td>商品名称</td>
        <td>商品价格</td>
        <td>库存数量</td>
        <td>商品简介</td>
        <td>开始时间</td>
        <td>结束时间</td>
        <td>开始秒杀</td>
    </tr>
    <tr th:each="goods,goodsStat : ${goodsList}">
        <td th:text="${goodsStat.index}+1"></td>
        <td th:text="${goods.name}"></td>
        <td th:text="${goods.price}"></td>
        <td th:text="${goods.stock}"></td>
        <td th:text="${goods.note}"></td>
        <td th:text="${#dates.format(goods.startTime,'yyyy-MM-dd HH:mm:ss')}"></td>
        <td th:text="${#dates.format(goods.endTime,'yyyy-MM-dd HH:mm:ss')}"></td>
        <td><button th:name="${goods.id}" onclick="doMiaosha(this)">秒杀</button> </td>
    </tr>
</table>
</body>
</html>